const express = require("express")
const Router = express.Router()
const path = require("path")
const moment = require("moment");
const nowDate = moment().format("YYYY-MM-DD");
const multer = require("multer")
const { verifyImage } = require("../../utils/verify")
const upload = require("./index.js")
// 头像文件夹




// 上传图片
// 自定义中间件

// 上传用户头像
Router.post("/", upload("avatar").single("avatar"), async (req, res) => {
    let { filename } = req.file
    // 正则验证
    let msg
    let isFlag = verifyImage(filename, (msg) => {
        msg = msg
    })
    if (!isFlag) {
        res.send(msg)
        return
    }
    if (req.file) {
        res.send({
            code: 0,
            msg: `http://192.168.0.197:3000/avatar/${nowDate}/${filename}`,
        })
    }
})





module.exports = Router